package com.urtime.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.urtime.util.ErrorJson;

public class ServletUtil {
    static protected void printError(HttpServletRequest request, HttpServletResponse response, int id, String info) throws IOException{
		response.setContentType("text/plain");
		response.getWriter().print(ErrorJson.getErrorJson(id,info));
		response.flushBuffer();
    }
    static protected boolean checkAccess(HttpServletRequest request, HttpServletResponse response) throws IOException{
    	HttpSession session=request.getSession(false);
    	if(session==null || session.getAttribute("userid")==null){
    		//response.getWriter().println("Login first 登录");
    		printError(request,response,ErrorJson.ERROR_NO_LOGIN, null);
    		return false;
    	}
		return true;
    }
}
